<template>
  <div class="network-container">
    <fm-nav-bar
      title="网络状态"
      :border="false"
      left-arrow
      @click-left="back"
    />
    <div class="box">
      <fm-image width="80" height="80" :src="network.img" />
      <div style="margin-top: 12px">{{ network.name }}</div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'NetworkInfo',
  data() {
    return {
      networkState: '',
      network: {
        name: '',
        img: '',
      },
    }
  },
  methods: {
    back() {
      this.$router.go(-1)
    },
    getNetworkInfo(network) {
      switch (network) {
        case 'none':
          this.network = {
            name: '无网络',
            img: require('@/assets/img/plugin/no-network.png'),
          }
          break
        case 'wifi':
          this.network = {
            name: 'WI-FI网络连接成功',
            img: require('@/assets/img/plugin/wifi-network.png'),
          }
          break
        case 'unknown':
          this.network = {
            name: '无网络',
            img: require('@/assets/img/plugin/no-network.png'),
          }
          break
        default:
          //包括ethernet、2g、3g、4g、cellular
          this.network = {
            name: '以太网/2G网络/蜂窝网络连接成功',
            img: require('@/assets/img/plugin/mobile-network.png'),
          }
          break
      }
    },
  },
  mounted() {
    if (typeof yuanchu != 'undefined') {
      this.networkState = yuanchu?.navigator?.network.connection.type
      this.getNetworkInfo(this.networkState)
    }
  },
}
</script>
<style lang="less" scoped>
.network-container {
  height: 100%;
  background-color: #f2f3f5;
  .box {
    margin-top: 96px;
    text-align: center;
    font-size: 28px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 600;
    color: #414b59;
    line-height: 40px;
  }
}
</style>